﻿using System.ComponentModel;
using System.Collections;
using System.Drawing.Design;
using System.Windows.Forms;

namespace UtfprLibrary.Windows.Forms.ComponentModel {
    /// <summary>
    /// TODO
    /// </summary>
    [Editor("UtfprLibrary.Windows.Forms.ComponentModel.UBNInitialValuedControlCollectionEditor, UtfprLibrary.WindowsForms.Design", typeof(UITypeEditor))]
    public class UBNInitialValuedControlCollection : CollectionBase {
        ///// <summary>
        ///// TODO
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="args"></param>
        //public delegate void AddingEventHandler(object sender, AddingChangedEventArgs args);

        ///// <summary>
        ///// TODO
        ///// </summary>
        //public event AddingEventHandler Adding;

        ///// <summary>
        ///// TODO
        ///// </summary>
        ///// <param name="control"></param>
        //private void AddingChanged(UtfprInitialValuedControl control) {
        //    if (Adding != null) {
        //        AddingChangedEventArgs args = new AddingChangedEventArgs(control);
        //        Adding(this, args);
        //    }
        //}

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool ContainsControl(Control item) {
            foreach (UtfprInitialValuedControl c in this.List) {
                if (c.Control.Equals(item)) {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public int GetItemIndex(Control item) {
            for (int i = 0; i < List.Count; i++) {
                if ((List[i] as UtfprInitialValuedControl).Control.Equals(item)) {
                    return i;
                }
            }

            return -1;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="item"></param>
        public void Add(UtfprInitialValuedControl item) {
            this.List.Add(item);
            //this.AddingChanged(item);
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="items"></param>
        public void AddRange(UBNInitialValuedControlCollection items) {
            foreach (UtfprInitialValuedControl i in items) {
                this.List.Add(i);
                //this.AddingChanged(i);
            }
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="item"></param>
        public void Remove(UtfprInitialValuedControl item) {
            this.List.Remove(item);
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="index"></param>
        public void Remove(int index) {
            if ((index > Count - 1) || (index < 0)) {
                throw new System.IndexOutOfRangeException();
            } else {
                this.List.RemoveAt(index);
            }
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public UtfprInitialValuedControl this[int i] {
            get { return (UtfprInitialValuedControl)this.List[i]; }
            set { this.List[i] = value; }
        }
    }
}
